<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SMSController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function sendMessage(Request $request){
    }

    public function daYuSend(Request $request){
        $uid = $request->input('uid');
        $pwd = $request->input('pwd');
        $tpl = $request->input('tpl');
        $mobile = $request->input('mobile');
        $param = $request->input('param');
        $smsType = $request->input('smsType');
        $freeSignName = $request->input('freeSignName');
        include_once ('/resources/assets/Dayu/TopSdk.php');
        $client = new \TopClient($uid, $pwd);
        $req = new \AlibabaAliqinFcSmsNumSendRequest();
        $req->setExtend("");
        $req->setSmsType($smsType);
        $req->setSmsFreeSignName($freeSignName);
        $req->setSmsParam($param);
        $req->setRecNum($mobile);
        $req->setSmsTemplateCode($tpl);
        $resp = $client->execute($req, false);
        if(isset($resp->success)){
            $res['status'] = 1;
        }else{
            $res['status'] = false;
            $res['msg'] = $resp->msg;
        }
        echo json_encode($res);
    }

    public function yzxSend(Request $request){
        $options['accountsid'] = $request->input('accountsid');
        $options['token'] = $request->input('token');
        $appId = $request->input('appId');
        $templateId = $request->input('templateId');
        $mobile = $request->input('mobile');
        $param = $request->input('param');
        //初始化 $options必填
        include_once ('/resources/assets/Ucpaas.class.php');
        $ucpass = new \Ucpaas($options);

        $arr=$ucpass->templateSMS($appId,$mobile,$templateId,$param);
        if (substr($arr,21,6) == 000000) {
            //如果成功就，这里只是测试样式，可根据自己的需求进行调节
//        return "短信验证码已发送成功，请注意查收短信";
            $res['status'] = 1;
        }else{
            //如果不成功
//        return "短信验证码发送失败，请联系客服";
            $res['status'] = false;
        }
        echo json_encode($res);
    }

    public function test(){
        $msg = array(
            'code' => '1234',
            'product' => '小徐'
        );
        $uid = '23272980';
        $pwd = '8d91efee0350711027672437d1939548';
        include_once ('/resources/assets/Dayu/TopSdk.php');
        $client = new \TopClient($uid, $pwd);
        $req = new \AlibabaAliqinFcSmsNumSendRequest();
        $req->setExtend("");
        $req->setSmsType('normal');
        $req->setSmsFreeSignName('青藤物业');
        $req->setSmsParam(json_encode($msg));
//        $req->setRecNum('13867558443');
        $req->setRecNum('15068745321');
        $req->setSmsTemplateCode('SMS_4260074');
        $resp = $client->execute($req, false);
        dd($resp);
    }
}
